<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="/shop/include :: header"></head>
<body>
<form class="layui-form" action="" lay-filter="shop_member_info-update-form" style="margin-top: 20px;">
    <div style="display: flex">
        <input name="id" th:value="${shopMemberInfo.id}"
               type="hidden">
        <div class="layui-form-item" style="display: contents">
            <label class="layui-form-label">头像：</label>
            <div class="layui-upload-list" id="test1">
                <img class="layui-upload-img" id="demo1" th:src="${shopMemberInfo.memberHead}" style="width: 300px;height: 300px">
                <input type="hidden" name="memberHead" id="memberHead" th:value="${shopMemberInfo.memberHead}">
            </div>
        </div>
        <div style="width: 63%">
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">昵称：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="nickName"
                           th:value="${shopMemberInfo.nickName}" name="nickName"
                           placeholder="请输入昵称">
                </div>
            </div>
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="userName"
                           th:value="${shopMemberInfo.userName}" name="userName"
                           placeholder="请输入用户名">
                </div>
            </div>
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="password"
                           th:value="${shopMemberInfo.password}" name="password"
                           placeholder="请输入密码">
                </div>
            </div>
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">手机号码：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="phone"
                           th:value="${shopMemberInfo.phone}" name="phone"
                           placeholder="请输入手机号码">
                </div>
            </div>
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="emial"
                           th:value="${shopMemberInfo.emial}" name="emial"
                           placeholder="请输入邮箱">
                </div>
            </div>
            <!--  -->
            <div class="layui-form-item">
                <label class="layui-form-label">签名：</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required" autocomplete="off" id="signature"
                           th:value="${shopMemberInfo.signature}" name="signature"
                           placeholder="请输入签名">
                </div>
            </div>
        </div>
    </div>
    <!--  -->
    <div class="layui-form-item">
        <label class="layui-form-label">绑定商户：</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-verify="required" autocomplete="off" id="merchantsId"
                   th:value="${shopMemberInfo.merchantsId}" name="merchantsId"
                   placeholder="请输入绑定商户">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">启用状态：</label>
        <div class="layui-input-block">
            <select name="enableState" id="enableState" placeholder="请选择启用状态">
                <option th:selected="${shopMemberInfo.enableState == 1}" value="1">正常</option>
                <option th:selected="${shopMemberInfo.enableState == 2}" value="2">注销</option>
                <option th:selected="${shopMemberInfo.enableState == 3}" value="3">冻结</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="shop_member_info-update">立即提交</button>
        </div>
    </div>
</form>
<div th:include="/shop/include::footer"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['layer', 'jquery', 'form', 'laydate', "upload"], function () {
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var upload = layui.upload;
        var form = layui.form;

        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/platform/UploadFile' //改成您自己的上传接口
            //, headers: {"token": layui.data(layui.setter.tableName)['token']}
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.status != "SUCCESS") {
                    return layer.msg('上传失败');
                }
                //上传成功
                layer.msg('上传成功');
                $("#memberHead").val(res.data)
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //监听提交
        form.on('submit(shop_member_info-update)', function (data) {
            $.ajax({
                url: '/platform/memberinfo/edit',
                type: "post",
                data: JSON.stringify(data.field),
                contentType: 'application/json; charset=utf-8', // 很重要
                async: false,
                success: function (result) {
                    if (result.status == "SUCCESS"){
                        layer.msg(result.message, {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            window.parent.location.reload();
                        });
                    }else {
                        layer.msg(result.message)
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>